package com.javase.补充_抽象类与接口.Q2;

public class Army {
    Weapon[] w;
    int i=0;
    public Army(int n) {
        this.w = new Weapon[n];
    }

    public void addWeapon(Weapon wa){
        w[i++]=wa;
    }

    public void attackAll(){
        for (int j = 0; j <w.length; j++) {
            w[j].attack();
        }
    }

    public void moveAll(){
        for (int j = 0; j <w.length; j++) {
            w[j].move();
        }
    }

    public static void main(String[] args) {
        Flighter flighter = new Flighter();
        Tank tank = new Tank();
        WarShip warShip = new WarShip();
        Army army = new Army(3);
        army.addWeapon(flighter);
        army.addWeapon(tank);
        army.addWeapon(warShip);
        army.attackAll();
        army.moveAll();
    }

}
